//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

#include "NoeudReseau.h"

#ifndef NeuroneReseauH
#include "NeuroneReseau.h"
#endif

#ifndef ReseauConceptsH
#include "ReseauConcepts.h"
#endif

#include <assert.h>
//---------------------------------------------------------------------------

#pragma package(smart_init)


__fastcall NoeudReseau::NoeudReseau()
{
  FReseau = NULL;
  for (int i = 0; i < ES_NBSens; i++) {
    FNeurones [i] = new NeuroneReseau(this);
  }
}

__fastcall NoeudReseau::~NoeudReseau()
{
  delete [] FNeurones;

  DereferencerNoeud();
}

void __fastcall NoeudReseau::AddLiaisonVers(NoeudReseau * n)
{
  assert (n != NULL);
  assert (FNeurones[ES_Sortie] != NULL);
  assert (n->FNeurones[ES_Entree] != NULL);

  FNeurones[ES_Sortie]->EtablirLiaisonAvec(n->FNeurones[ES_Entree]);
}

void __fastcall NoeudReseau::RemoveLiaisonVers(NoeudReseau * n)
{
  assert (n != NULL);
  assert (FNeurones[ES_Sortie] != NULL);
  assert (n->FNeurones[ES_Entree] != NULL);

  FNeurones[ES_Sortie]->SuppimerLiaisonAvec(n->FNeurones[ES_Entree]);

}

void __fastcall NoeudReseau::Detacher(void)
{
  for (int i = 0; i < ES_NBSens; i++) {
    FNeurones [i]->Detacher();
  }
}

void __fastcall NoeudReseau::SeReferencer(void)
{
  ReferencerNoeud();
}

void __fastcall NoeudReseau::SeDereferencer(void)
{
  DereferencerNoeud();
}

void __fastcall NoeudReseau::SetReseau(ReseauConcepts * value)
{
  if(FReseau != value) {
    if (FReseau != NULL) {
      SeDereferencer();
    }

    FReseau = value;

    if (FReseau != NULL) {
      SeReferencer();
    }
  }
}

void __fastcall NoeudReseau::ReferencerNoeud(void)
{
  if (FReseau != NULL)
    FReseau->AddNoeud(this);
}

void __fastcall NoeudReseau::DereferencerNoeud(void)
{
  if (FReseau != NULL) {
    FReseau->SupprimerNoeud(this);
  }
}

void __fastcall NoeudReseau::SynchroniserAvecReseau(void)
{
  assert (FReseau != NULL);

  FInstantLastActivation = FReseau->Instant;
}

void __fastcall NoeudReseau::ActivationExterne(void)
{
  assert (FReseau != NULL);

  FInstantLastActivation = FReseau->Instant;

  //TODO:ecrire la procedure
}
